/**
 * 移液管
 */
Yiyeguan = Widget.extend({
	ctor:function(){
		this._super();
		this.init();
		this.setTag(TAG_YYG_YYG);
	},
	init:function(){
		this.body = new Button(this, 21, TAG_YYG, "#yiyeguan.png", this.callback);
		
		var hand = new Button(this, 20, TAG_YYG1_RIGHT, "#hand_right.png", this.callback);
		hand.setPosition(cc.p(32,150));
		hand.setVisible(false);
		var part = new Button(this, 21, TAG_YYG1_RIGHT_PART, "#hand_right_part.png", this.callback);
		part.setPosition(cc.p(32,150));
		part.setVisible(false);
		//食指堵住手势
		var hand1 = new Button(this, 20, TAG_YYG1_RIGHT1, "#yyg_hand1.png", this.callback);
		hand1.setPosition(cc.p(53,145));
		hand1.setVisible(false);
		var hand2 = new Button(this, 21, TAG_YYG1_RIGHT2, "#yyg_hand2.png", this.callback);
		hand2.setPosition(cc.p(53,145));
		hand2.setVisible(false);
		var part2 = new Button(this, 21, TAG_YYG1_RIGHT_PART2, "#yyg_hand_part.png", this.callback);
		part2.setPosition(cc.p(53,145));
		part2.setVisible(false);

		// 水位线
		var line = new cc.Sprite("#cyl.png");
		line.setOpacity(0);
		line.setPosition(21, 20 );
		line.setScale(0.6);
		this.body.addChild(line, 12, TAG_YYG_LINE);
		//手势
		var hand = new Button(this.body, 20, TAG_HAND, "#hand.png", this.callback);
		hand.setPosition(cc.p(40,410));
		hand.setVisible(false);
		
		this.body.setCascadeOpacityEnabled(true);
		this.callNext = cc.callFunc(function(){
		gg.flow.next();
		}, this);
		this.callNext.retain();
	},
	yyg_start:function(p,q){
		var rot=cc.rotateTo(0.1, 0);
		var move=cc.moveTo(0.6, p);
		var move1=cc.moveTo(0.6, q);
		var seq=cc.sequence(rot,move,move1,this.callNext);
		this.runAction(seq);
	},
	yyg_lineUp:function(pos){
		var line = this.getChildByTag(TAG_YYG).getChildByTag(TAG_YYG_LINE);
		var show = cc.fadeTo(0.5,255);
		var move = cc.moveTo(0.9,cc.p(pos.x,pos.y));
		var sca=cc.scaleTo(0.9, 2.5, 1);
		var spa=cc.spawn(move,sca);
		var move1=cc.moveTo(0.6,cc.p(pos.x,(pos.y-50)))
		var seq = null;
		seq = cc.sequence(show, move1,spa);
		line.runAction(seq);
	},
	yyg_lineDown:function(pos){
		var line = this.getChildByTag(TAG_YYG).getChildByTag(TAG_YYG_LINE);
		var move = cc.moveTo(0.9,cc.p(pos.x,(pos.y+120)));
		var sca=cc.scaleTo(0.9, 0.6, 1);
		var spa=cc.spawn(move,sca);
		var move1=cc.moveTo(0.6,cc.p(pos.x,pos.y))
		var seq = null;
		seq = cc.sequence(spa,move1);
		line.runAction(seq);
	},
	//滴定管横向转动清洗动画
	yygClean:function(){
		var hand_left = new Button(this, 19, TAG_YYG2_LEFT, "#hand_left.png", this.callback);
		hand_left.setPosition(cc.p(55,-106));
		hand_left.setRotation(-140);
		var hand_left_part = new Button(this, 21, TAG_YYG2_LEFT_PART, "#hand_left_part.png", this.callback);
		hand_left_part.setPosition(cc.p(55,-106));
		hand_left_part.setRotation(-140);
		
		var hand_right = new Button(this, 19, TAG_YYG2_RIGHT, "#hand_right.png", this.callback);
		hand_right.setPosition(cc.p(55,150));
		hand_right.setRotation(-40);
		var hand_right_part = new Button(this, 21, TAG_YYG2_RIGHT_PART, "#hand_right_part.png", this.callback);
		hand_right_part.setPosition(cc.p(55,150));
		hand_right_part.setRotation(-40);
		
		var yyg = new cc.Sprite("#yyg/yyg_1.png");
		yyg.setPosition(0, 0);
		yyg.setRotation(-90);
		this.addChild(yyg, 20, TAG_YYG_CLEAN);

		var animFrames = [];
		for (var i = 1; i < 6; i++) {
			var str = "yyg/yyg_" + i + ".png";
			var frame = cc.spriteFrameCache.getSpriteFrame(str);
			animFrames.push(frame);
		}
		var animation = new cc.Animation(animFrames, 0.15,2);
		var action = cc.animate(animation);
		var seq=cc.sequence(action,cc.callFunc(function() {
			yyg.removeFromParent();
			hand_left.removeFromParent();
			hand_left_part.removeFromParent();
			hand_right.removeFromParent();
			hand_right_part.removeFromParent();
		}, this));
		yyg.runAction(seq);
	},
	callback:function(p){
		var yyg=this.getChildByTag(TAG_YYG);
		var beaker=this.getParent().getChildByTag(TAG_BEAKER);			
		
		
		var hand=this.getChildByTag(TAG_YYG1_RIGHT);				
		var part=this.getChildByTag(TAG_YYG1_RIGHT_PART);
		var hand1=this.getChildByTag(TAG_YYG1_RIGHT1);	
		var hand2=this.getChildByTag(TAG_YYG1_RIGHT2);				
		var part2=this.getChildByTag(TAG_YYG1_RIGHT_PART2);
		var action=gg.flow.flow.action;
		switch(p.getTag()){
		case TAG_YYG:
			if(action==ACTION_DO1){
				hand.setVisible(true);
				part.setVisible(true);
				this.yyg_start(cc.p(960,400),cc.p(960,306));
			}else if(action==ACTION_DO2){				
			
			}else if(action==ACTION_DO3){

			}else if(action==ACTION_DO4){
				var mov=cc.moveTo(0.6, cc.p(500,150));
				var move = cc.moveTo(0.6,cc.p(0,50));
				var rot=cc.rotateTo(1, 90);
				var fadeout=cc.fadeOut(0);
				var fadein=cc.fadeIn(0);
				var rot1 = cc.rotateTo(0.6, 0);
				var move1=cc.moveTo(0.6, cc.p(330,140));		
				var seq = cc.sequence(cc.delayTime(0.2),cc.callFunc(function() {
					hand.setVisible(true);
				}, this),cc.delayTime(0.3),mov,move,cc.callFunc(function() {
					var line = this.getChildByTag(TAG_YYG).getChildByTag(TAG_YYG_LINE);									
					var rot2=cc.rotateTo(1, -90);
					var sca2=cc.scaleTo(1, 4.5,1);
					var fadeout2=cc.fadeOut(1);
					var spa2=cc.spawn(rot2,sca2,fadeout2);								
					var rot1=cc.rotateTo(0.6, 0);
					var sca1=cc.scaleTo(0.6, 2.5,1);
					var fadein=cc.fadeIn(0.6);
					var spa1=cc.spawn(rot1,sca1,fadein);
					var seq=cc.sequence(spa2,cc.delayTime(1.4),spa1);
					line.runAction(seq);
				}, this),rot,fadeout,cc.callFunc(function() {
					this.yygClean();
					hand.setVisible(false);
				},this),cc.delayTime(1.5),fadein,rot1,move1,cc.callFunc(function() {
					this.getParent().water.flowDown(cc.p(840,200),0.8);
					beaker.lineUp(false,cc.p(0,2));
					this.yyg_lineDown(cc.p(20,10));
				},this),cc.delayTime(1.7),move,this.func);	
				yyg.runAction(seq);
			}else if(action==ACTION_DO5){
				hand.setVisible(true);
				part.setVisible(true);
				this.yyg_start(cc.p(960,400),cc.p(960,306));
			}else if(action==ACTION_DO6){
				var move2=cc.moveTo(0.6, cc.p(960,410));
				var move3=cc.moveTo(0.6, cc.p(833,362));
				var move4=cc.moveTo(0.6, cc.p(500,400));
				var seq=cc.sequence(move2,move3,cc.callFunc(function() {
					hand1.setSpriteFrame("yyg_hand2.png");
					this.getParent().water.flowDown(cc.p(840,200),0.8);
					beaker.lineUp(false,cc.p(0,1));
					var line = this.getChildByTag(TAG_YYG).getChildByTag(TAG_YYG_LINE);
					line.runAction(cc.moveTo(1,cc.p(20,360) ));
					var p0=new cc.Sprite("#0_0.png");
					p0.setCascadeOpacityEnabled(true);
					p0.setPosition(cc.p(-100,119));
					this.addChild(p0);
					var seq=cc.sequence(cc.delayTime(2),cc.fadeOut(0));
					p0.runAction(seq);
					
					var line3=new cc.Sprite("#cyl.png");
					line3.setScale(3.2,2.5);
					line3.setPosition(112,70);
					p0.addChild(line3);
					line3.runAction(cc.moveTo(1,cc.p(112,54)));
				}, this),cc.delayTime(2),cc.callFunc(function() {
					hand1.setSpriteFrame("yyg_hand1.png");
				}, this),move4,cc.callFunc(function() {
					var jianye=this.getParent().getChildByTag(TAG_JIANYE_BOTTLE);
					jianye.removeFromParent();
				}, this),this.callNext);
				this.runAction(seq);
			}else if(action==ACTION_DO7){
				var move=cc.moveTo(0.6, cc.p(565,400));
				var move1=cc.moveTo(0.6, cc.p(565,325));
				var move2=cc.moveTo(0.6, cc.p(565,400));
				var seq=cc.sequence(move,move1,cc.callFunc(function() {
					hand1.setSpriteFrame("yyg_hand2.png");
					var line = this.getChildByTag(TAG_YYG).getChildByTag(TAG_YYG_LINE);
					var mov1=cc.moveTo(0.6, cc.p(21,284));
					var mov2=cc.moveTo(0.6, cc.p(21,270));
					var sca1=cc.scaleTo(0.6,2.5,1 );
					var spa1=cc.spawn(mov2,sca1);
					var mov3=cc.moveTo(0.6, cc.p(21,190));
					var mov4=cc.moveTo(0.6, cc.p(21,160));
					var sca2=cc.scaleTo(0.6, 0.6);
					var spa2=cc.spawn(mov4,sca2);
					var mov5=cc.moveTo(0.6, cc.p(21,7));
					var fad=cc.fadeOut(0);
					var seq=cc.sequence(mov1,spa1,mov3,spa2,mov5,fad);
					line.runAction(seq);
					this.getParent().water.flowDown(cc.p(570,156),2);
				}, this),cc.delayTime(3),move2,this.callNext);
				this.runAction(seq);
				
				var zzz=this.getParent().getChildByTag(TAG_ZHUI_BOTTLE);
				var zhui=this.getParent().getChildByTag(TAG_ZHUI_BOTTLE).getChildByTag(TAG_ZHUIXINGPING);
				var hand=this.getParent().getChildByTag(TAG_ZHUI_BOTTLE).getChildByTag(TAG_LEFT);
				var part=this.getParent().getChildByTag(TAG_ZHUI_BOTTLE).getChildByTag(TAG_LEFT_PART);
				hand.setVisible(true);
				part.setVisible(true);
				var rot=cc.rotateTo(0.6, 20);
				var rot1=cc.rotateTo(0.6, 0);
				var seq1=cc.sequence(rot,cc.delayTime(0.9),cc.callFunc(function() {
					this.getParent().zhuixingping.lineUp();
				}, this),cc.delayTime(3),rot1,cc.callFunc(function() {
					zhui.setSpriteFrame("zhui.png");
					var line=this.getParent().getChildByTag(TAG_ZHUI_BOTTLE).getChildByTag(TAG_ZHUI_LINE);
					line.removeFromParent();				
					this.removeFromParent();	
					hand.setVisible(false);
					part.setVisible(false);
				}, this));
				zzz.runAction(seq1);
			}else if(action==Y1){				
				var mov=cc.moveTo(0.6, cc.p(960,400));
				var move = cc.moveTo(0.6,cc.p(570,250));
				var rot=cc.rotateTo(1, 90);
				var fadeout=cc.fadeOut(0);
				var fadein=cc.fadeIn(0);
				var rot1 = cc.rotateTo(0.6, 0);
				var move1=cc.moveTo(0.6, cc.p(833,362));		
				var seq = cc.sequence(mov,move,cc.callFunc(function() {
					var line = this.getChildByTag(TAG_YYG).getChildByTag(TAG_YYG_LINE);									
					var rot2=cc.rotateTo(1, -90);
					var sca2=cc.scaleTo(1, 4.5,1);
					var fadeout2=cc.fadeOut(1);
					var spa2=cc.spawn(rot2,sca2,fadeout2);								
					var rot1=cc.rotateTo(0.6, 0);
					var sca1=cc.scaleTo(0.6, 2.5,1);
					var fadein=cc.fadeIn(0.6);
					var spa1=cc.spawn(rot1,sca1,fadein);
					var seq=cc.sequence(spa2,cc.delayTime(1.4),spa1);
					line.runAction(seq);
				}, this),rot,cc.callFunc(function() {
					this.yygClean();
					yyg.runAction(cc.fadeOut(0));					
					hand1.setVisible(false);
					part2.setVisible(false);
				},this),cc.delayTime(1.5),cc.callFunc(function() {
					yyg.runAction(cc.fadeIn(0));
					hand1.setVisible(true);
					part2.setVisible(true);
				}, this),rot1,move1,cc.callFunc(function() {
					hand1.setSpriteFrame("yyg_hand2.png");
					this.getParent().water.flowDown(cc.p(840,200),0.8);
					beaker.lineUp(false,cc.p(0,1));
					this.yyg_lineDown(cc.p(20,10));
				},this),cc.delayTime(1.7),move,cc.callFunc(function() {
					hand1.setVisible(false);
					part2.setVisible(false);
					var show=new ShowTip("同样方法，用自来水再重复清洗移液管2次" ,cc.p(900,250));
				}, this),cc.delayTime(1),cc.callFunc(function() {
					var beaker2=this.getParent().getChildByTag(TAG_BEAKER2);
					beaker2.removeFromParent();
				}, this),this.callNext);	
				this.runAction(seq);						
			}else if(action==Y2){				
				var mov=cc.moveTo(0.6, cc.p(960,400));
				var move = cc.moveTo(0.6,cc.p(570,250));
				var rot=cc.rotateTo(1, 90);
				var fadeout=cc.fadeOut(0);
				var fadein=cc.fadeIn(0);
				var rot1 = cc.rotateTo(0.6, 0);
				var move1=cc.moveTo(0.6, cc.p(833,362));		
				var seq = cc.sequence(mov,move,cc.callFunc(function() {
					var line = this.getChildByTag(TAG_YYG).getChildByTag(TAG_YYG_LINE);									
					var rot2=cc.rotateTo(1, -90);
					var sca2=cc.scaleTo(1, 4.5,1);
					var fadeout2=cc.fadeOut(1);
					var spa2=cc.spawn(rot2,sca2,fadeout2);								
					var rot1=cc.rotateTo(0.6, 0);
					var sca1=cc.scaleTo(0.6, 2.5,1);
					var fadein=cc.fadeIn(0.6);
					var spa1=cc.spawn(rot1,sca1,fadein);
					var seq=cc.sequence(spa2,cc.delayTime(1.4),spa1);
					line.runAction(seq);
				}, this),rot,fadeout,cc.callFunc(function() {
					this.yygClean();
					yyg.runAction(cc.fadeOut(0));	
					hand1.setVisible(false);
					part2.setVisible(false);
				},this),cc.delayTime(1.5),cc.callFunc(function() {
					yyg.runAction(cc.fadeIn(0));
					hand1.setVisible(true);
					part2.setVisible(true);
				}, this),rot1,move1,cc.callFunc(function() {
					hand1.setSpriteFrame("yyg_hand2.png");
					this.getParent().water.flowDown(cc.p(840,200),0.8);
					beaker.lineUp(false,cc.p(0,1));
					this.yyg_lineDown(cc.p(20,10));
				},this),cc.delayTime(1.7),move,cc.callFunc(function() {
					hand1.setVisible(false);
					part2.setVisible(false);
					var show=new ShowTip("同样方法，用蒸馏水再重复清洗移液管2次" ,cc.p(900,250));
				}, this),cc.delayTime(1),cc.callFunc(function() {
					var beaker3=this.getParent().getChildByTag(TAG_BEAKER3);
					beaker3.removeFromParent();
				}, this),this.callNext);	
				this.runAction(seq);						
			}else if(action==Y3){
				var mov=cc.moveTo(0.6, cc.p(960,410));
				var move = cc.moveTo(0.6,cc.p(570,250));
				var rot=cc.rotateTo(1, 90);
				var fadeout=cc.fadeOut(0);
				var fadein=cc.fadeIn(0);
				var rot1 = cc.rotateTo(0.6, 0);
				var move1=cc.moveTo(0.6, cc.p(833,362));		
				var seq = cc.sequence(mov,move,cc.callFunc(function() {
					var line = this.getChildByTag(TAG_YYG).getChildByTag(TAG_YYG_LINE);									
					var rot2=cc.rotateTo(1, -90);
					var sca2=cc.scaleTo(1, 4.5,1);
					var fadeout2=cc.fadeOut(1);
					var spa2=cc.spawn(rot2,sca2,fadeout2);								
					var rot1=cc.rotateTo(0.6, 0);
					var sca1=cc.scaleTo(0.6, 2.5,1);
					var fadein=cc.fadeIn(0.6);
					var spa1=cc.spawn(rot1,sca1,fadein);
					var seq=cc.sequence(spa2,cc.delayTime(1.4),spa1);
					line.runAction(seq);
				}, this),rot,fadeout,cc.callFunc(function() {
					this.yygClean();
					yyg.runAction(cc.fadeOut(0));	
					hand1.setVisible(false);
					part2.setVisible(false);
				},this),cc.delayTime(1.5),cc.callFunc(function() {
					yyg.runAction(cc.fadeIn(0));
					hand1.setVisible(true);
					part2.setVisible(true);
				}, this),rot1,move1,cc.callFunc(function() {
					hand1.setSpriteFrame("yyg_hand2.png");
					this.getParent().water.flowDown(cc.p(840,200),0.8);
					beaker.lineUp(false,cc.p(0,1));
					this.yyg_lineDown(cc.p(20,10));
				},this),cc.delayTime(1.7),move,cc.callFunc(function() {
					hand1.setVisible(false);
					part2.setVisible(false);
					var show=new ShowTip("同样方法，用该待测液再重复清洗移液管2次" ,cc.p(900,263));
				}, this),cc.delayTime(1),this.callNext);	
				this.runAction(seq);
			}
			break;
		}
	},
	onExit:function(){
	this._super();
	this.callNext.release();
	}
});